<script type="text/javascript">
var content = null;
$(function () {
	addFilesUploadEvent();
	if(CKEDITOR.instances['content']) 
		CKEDITOR.remove(CKEDITOR.instances['content']);
	
	var uploadParm = {
		height:'270px',
		filebrowserBrowseUrl:'${contextPath}browse-file.html',
		filebrowserImageBrowseUrl:'${contextPath}browse-image.html',
		filebrowserUploadUrl:'${contextPath}m/organdetail-upload.html?type=file',
		filebrowserImageUploadUrl:'${contextPath}m/organdetail-upload.html?type=image',
		language:'zh-cn',
	}
	content = CKEDITOR.replace('content', uploadParm);
});

function save() {
	var parm = $('#editOrganDetailForm').serialize() + '&content=' + fixJqText(Url.encode(content.getData()));
	var url = create_url('organdetail-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
		sys_submiting_close();
			if ('success' == result) {
				sys_msg('保存成功');
				sys_load_handle('organdetail');
			}
		}
	});
}

function addFilesUploadEvent() {
	var url = create_url('organdetail-uploads');
	var btn = $('#uploadFilesBtn');
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(jpg|png|jpeg|gif|bmp|JPG|PNG|JPEG|GIF|BMP)$/.test(ext)){
				this.setData({
					'info':'文件类型正确'
				});
			} else {
					alert('文件类型错误', '只能上传类型为：jpg、png、jpeg、gif、bmp、图片文件!建议图片尺寸小于200*200最佳');
				return false;                    
			}
			$('#upload_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_warning('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_warning('文件类型错误', '只能上传类型为：JGP、GIF、BMP、ICO、PNG的文件!');
			else {
				var template = $('#tempAnnexListDiv').find('.rep');
				var annexList = $('#annexListTable');
				var index = parseInt($('#organDetail_an_index').val());
				$.each(response.list, function(i) {
					var pii = template.clone(true);
					pii.find('.title').html(response.list[i].name).end()
						.find('.name').attr('name', 'List[' + (index + i) + '].name').val(response.list[i].name).end()
						.find('.size').attr('name', 'List[' + (index + i) + '].size').val(response.list[i].size).end()
						.find('.sn').attr('name', 'List[' + (index + i) + '].sn').val(response.list[i].path).end()
						.find('.ext').attr('name', 'List[' + (index + i) + '].ext').val(response.list[i].ext).end()
						.find('.afcs').val(response.list[i].code).end();
					annexList.append(pii);
					index ++;
				});
				this.enable();
				$('#organDetail_an_index').val(index);
			}
		}
	});
}
function deleteSelectedItem(btn) {
	btn.parents('.rep').remove();
}
</script>
<div class="widget" style="float:left; width:720px;">
	<div class="widget-header">
		<h3 class="title"><i class="fontello-icon-th-list-1"></i> 编辑公司简介</h3>
	</div>
	<div class="widget-content">
		<form id="editOrganDetailForm">
			<input type="hidden" name="oc" value="${(cu_organCode)!''}"/>
			<input type="hidden" name="code" value="${(od.code)!''}"/>
			<table class="table boo-table table-content" style="width:100%; text-align:left;">
				<tr>
					<td class="table-left" style="width:100px;">简介内容</td>
					<td><textarea id="content" style="width:1000px;height:800px;">${(od.content)!''}</textarea></td>
				</tr>
				<tr>
					<td class="table-left" style="width:100px;">公司图片<a id="uploadFilesBtn" href="javascript:;">[选择]</a></td>
					<td id="annexListTable">
						<#if list??>
							<#list list as oda>
								<div class="filter-table rep" style="margin-left:5px; margin-bottom:0px;">
									<input type="hidden" name="list[${oda_index}].code" value="${oda.code}" />
									<button type="button" class="close" data-dismiss="alert" onclick="javascript:deleteSelectedItem($(this));">&times;</button>
									<a class="title" target="_blank" href="${contextPath}upload/organDetailAnnex/${oda.sn}${oda.ext}">${oda.name}</a>
								</div>
							</#list>
						</#if>
					</td>
				</tr>
				<tr>
					<td colspan="2" style="text-align:center;">
						<a href="javascript:;" class="btn btn-info" onclick="javascript:save();">
							<i class="fontello-icon-mail-4"></i>&nbsp;保&nbsp;&nbsp;存
						</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="javascript:;" class="btn btn-info" onclick="javascript:sys_load_handle('organdetail');">
							<i class="fontello-icon-block"></i>&nbsp;重&nbsp;&nbsp;置
						</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>

<div id="tempAnnexListDiv" style="display:none;">
	<div class="filter-table rep" style="margin-left:5px; margin-bottom:0px;">
		<input class="name" type="hidden" />
		<input class="size" type="hidden" />
		<input class="sn" type="hidden"  />
		<input class="ext" type="hidden"  />
		<input class="afcs" type="hidden" name="afcs"  />
		<button type="button" class="close" data-dismiss="alert" onclick="javascript:deleteSelectedItem($(this));">&times;</button>
		<a class="title" href="#"></a>
	</div>
</div>
<input type="hidden" id="organDetail_an_index" value="0" />